home *** CD-ROM | disk | FTP | other *** search
- #include "main.h"
-
- #define modsWord 3
- #define shiftBit 1
- #define alphaBit 2
- #define optionBit 4
- #define cmdBit 0x8000
-
- windowAt( h, v )
- int h, v;
- {
- WindowPeek theWindow;
-
- theWindow = (WindowPeek)FrontWindow();
- while( theWindow )
- {
- if(( h == - theWindow->port.portBits.bounds.left ) &&
- ( v == - theWindow->port.portBits.bounds.top ))
- return( -1 );
- theWindow = theWindow->nextWindow;
- }
- return( 0 );
- }
-
- newCorner( h, v )
- int *h, *v;
- {
- Point old;
- int sequence = 0, height;
-
- height = getMBarHeight();
- old.h = 16;
- old.v = 33 + height;
- while( windowAt( old.h, old.v )) {
- old.h += 16;
- old.v += 16;
- if( !PtInRgn( old, GrayRgn )) {
- sequence = ( sequence + 2 ) % 16;
- old.h = 16 - sequence;
- old.v = sequence + 33 + height;
- }
- }
- *h = old.h;
- *v = old.v;
- }
-
- getDataFontInfo( theFont, which )
- dataFontPtr theFont;
- int which;
- {
- GrafPort tempPort;
- GrafPtr savePort;
- FontInfo theFontInfo;
- char theString[ pasStrLen ];
-
- GetIndString( theString, fontNames, which );
- if( !*theString ) theFont->number = 0;
- else GetFNum( theString, &theFont->number );
- GetIndString( theString, fontSizeStrs, which );
- theFont->size = readPasNum( theString );
- theFont->size = max( theFont->size, minFontSize );
-
- GetPort( &savePort );
- OpenPort( &tempPort );
- TextFont( theFont->number );
- TextSize( theFont->size );
- TextFace( 0 );
-
- GetFontInfo( &theFontInfo );
- theFont->topStart = theFontInfo.ascent + topMargin;
- theFont->topSpace = theFont->topStart + theFontInfo.descent + theFontInfo.leading + topMargin + 2;
-
- GetIndString( theString, statStrings, genStr );
- if( *theString ) theFont->genStart = StringWidth( theString );
- else theFont->genStart = StringWidth( "\pGeneration: " );
- theFont->genStart += leftMargin;
- SetPort( savePort );
- ClosePort( &tempPort );
- }
-
- /*******************************************************
- * *
- * For now, this routine simply sets the minimum to a default which keeps the *
- * generation routines and such happy, and sets the maximum to very large. In *
- * future, it could check against GrayRgn bounding box for the maximum. *
- * *
- *******************************************************/
-
- setSizeRect( theRect, theWindow )
- Rect *theRect;
- WindowPtr theWindow;
- {
- dataHandle theDataHand;
-
- theRect->bottom = theRect->right = 32767;
- theRect->left = 63;
- theDataHand = ( dataHandle )GetWRefCon( theWindow );
- theRect->top = 63 + ( **theDataHand ).theFont.topSpace;
- }
-
- readPasNum( source )
- char *source;
- {
- int length, result = 0;
-
- length = ( int )*source++;
- if( length )
- while( length-- && *source >= '0' && *source <= '9' )
- result = result * 10 + *source++ - '0';
- if( length > -1 ) result = 0;
- return( result );
- }
-
- getModifiers() {
- int theKeys[ 8 ];
- register int mods, result = 0;
-
- GetKeys( theKeys );
- mods = theKeys[ modsWord ];
- if( mods & shiftBit ) result |= shiftKey;
- if( mods & alphaBit ) result |= alphaLock;
- if( mods & optionBit ) result |= optionKey;
- if( mods & cmdBit ) result |= cmdKey;
- return( result );
- }
-
- long timer()
- {
- static long myEvents = 0;
-
- return( myEvents++ );
- }
-
- setBigRgn( theRgn )
- RgnHandle theRgn;
- {
- SetRectRgn( theRgn, -32768, -32768, 32767, 32767 );
- }
-
- /*******************************************************
- * *
- * CopyBig is an exact equivalent of CopyBits (and as such is capitalized). It *
- * merely ensures that CopyBits is never called with more than maxCopyBits *
- * bytes of data to copy. Currently it repeatedly calls with the original mask *
- * region. It may be more efficient to repeatedly clip to smaller portions of the *
- * mask. That is, intersect it with a rectangle that repeatedly gets lower. *
- * *
- *******************************************************/
-
- CopyBig( source, dest, sourceRect, destRect, mode, mask )
- BitMap *source, *dest;
- Rect *sourceRect, *destRect;
- int mode;
- RgnHandle mask;
- {
- int remaining, increment, factor;
- Rect lsource, ldest;
-
- startMyCopy();
- remaining = sourceRect->bottom - sourceRect->top;
- factor = ( sourceRect->right - sourceRect->left + 7 ) >> 3;
- if( factor == 0 ) factor = 1;
- increment = maxCopyBits / factor;
- lsource = *sourceRect;
- ldest = *destRect;
- while( remaining > increment )
- {
- lsource.bottom = lsource.top + increment;
- ldest.bottom = ldest.top + increment;
- CopyBits( source, dest, &lsource, &ldest, mode, mask );
- lsource.top = lsource.bottom;
- ldest.top = ldest.bottom;
- remaining -= increment;
- }
- lsource.bottom = sourceRect->bottom;
- ldest.bottom = destRect->bottom;
- CopyBits( source, dest, &lsource, &ldest, mode, mask );
- endMyCopy();
- }
-
- /*******************************************************
- * *
- * This allocates a new pointer direcly using the system call, and sets the clear *
- * flag when it does so. *
- * *
- *******************************************************/
-
- char *NewPtrClear( size )
- long size;
- {
- char *ret;
-
- asm {
- move.l size,d0
- NewPtr CLEAR
- move.l a0,ret
- }
- return( ret );
- }
-
- /*******************************************************
- * *
- * PtrToPtr is much like HandToHand - it takes a ptr*, and replaces the given *
- * pointer to a new one with the same contents. *
- * *
- *******************************************************/
-
- ptrToPtr( ptr )
- char **ptr;
- {
- long size;
- char *new;
-
- size = GetPtrSize( *ptr );
- new = NewPtr( size );
- BlockMove( *ptr, new, size );
- *ptr = new;
- }
-
- /*******************************************************
- * *
- * RgnIsRect returns true if the given region exactly equals the given rectangle. *
- * *
- *******************************************************/
-
- rgnIsRect( theRgn, theRect )
- RgnHandle theRgn;
- Rect *theRect;
- {
- RgnHandle tempRgn;
- int result;
-
- tempRgn = NewRgn();
- RectRgn( tempRgn, theRect );
- result = EqualRgn( tempRgn, theRgn );
- DisposeRgn( tempRgn );
- return( result );
- }
-
- /*******************************************************
- * *
- * SetRectBits initializes the given BitMap to exactly contain the given rectangle. *
- * It will always set rowBytes to a multiple of 4. *
- * *
- *******************************************************/
-
- setRectBits( theBits, theRect )
- BitMap *theBits;
- Rect *theRect;
- {
- theBits->bounds = *theRect;
- theBits->rowBytes = (( theRect->right - theRect->left + 31 ) >> 3 ) & longMask;
- theBits->baseAddr = NewPtrClear( (long)( theRect->bottom - theRect->top ) * theBits->rowBytes );
- }
-
- /*******************************************************
- * *
- * displayNumPas takes the number ( a long ), and the address of the *last* *
- * character in the destination array. It returns the address of the count. It is *
- * used both to convert the free memory count for the about box and to convert *
- * the generation count used in the automata windows. *
- * *
- *******************************************************/
-
- displayNumPas( num, end, result )
- long num;
- char *end;
- char **result;
- {
- int digits;
- char *realend = end;
-
- if( num )
- for( digits = 0; num; ++digits, num /= 10 ) {
- if( digits && ( digits % 3 == 0 ))
- *end-- = ',';
- *end-- = num % 10 + '0';
- }
- else *end-- = '0';
- *end = realend - end; /* calculate pascal length */
- *result = end;
- }
-
-